/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package server;

import DAO.StatusDAO;
import DAO.TagDAO;
import DAO.UserDAO;
import Testing.app;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.cassandra.thrift.*;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;
import pojo.Tag;
/**
 *
 * @author huy
 */
public class UserImpl implements User.Iface{

    private TTransport tr;
    private Cassandra.Client client;
    public UserImpl()
    {
        try {
            tr = new TFramedTransport(new TSocket(common.Constants.HOST, common.Constants.PORT));
            TProtocol proto = new TBinaryProtocol(tr);
            client = new Cassandra.Client(proto);
            tr.open();
            client.set_keyspace(common.Constants.KEYSPACE);
        } catch (InvalidRequestException ex) {
            Logger.getLogger(UserImpl.class.getName()).log(Level.SEVERE, null, ex);
        } catch (TException ex) {
            Logger.getLogger(UserImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    @Override
    public String selectRandom(){
        StatusDAO status_DAO = StatusDAO.getInstance(client);
        String result = status_DAO.SelectRandom();
        //tr.close();
        return result;
    }

    @Override
    public String selectRandomtoTag(String NameTag){
        StatusDAO status_DAO = StatusDAO.getInstance(client);
        String result = status_DAO.SelectRandomtoTag(NameTag);
        //tr.close();
        return result;
    }

    @Override
    public boolean savefavoriteStatus(String UseriD, String StatusID){
        UserDAO user_DAO = UserDAO.getInstance(client);
        boolean result = user_DAO.savefavoriteStatus(UseriD, StatusID);
        //tr.close();
        return result;
    }

    @Override
    public String selectfavoriteStatus(String UserID){
        UserDAO user_DAO = UserDAO.getInstance(client);
        String result = user_DAO.selectfavoriteStatus(UserID);
        //tr.close();
        return result;
    }

    @Override
    public boolean deletefavoriteStatus(String UserID, String StatusID){
        UserDAO user_DAO = UserDAO.getInstance(client);
        boolean result = user_DAO.deletefavoriteStatus(UserID, StatusID);
        //tr.close();
        return result;
    }

    @Override
    public String listOutstandingStatus(){
        StatusDAO status_DAO = StatusDAO.getInstance(client);
        String result = status_DAO.listOutstandingStatus();
        //tr.close();
        return result;
    }

    @Override
    public boolean inscreaseLikecount(String StatusID){
        StatusDAO status_DAO = StatusDAO.getInstance(client);
        boolean result = status_DAO.increaseLikecount(StatusID);
        //tr.close();
        return result;
    }

    @Override
    public boolean inscreaseDislikecount(String StatusID){
        StatusDAO status_DAO = StatusDAO.getInstance(client);
        boolean result = status_DAO.increaseDislikecount(StatusID);
        //tr.close();
        return result;
    }

    @Override
    public String listTag(){
        TagDAO tag_DAO = TagDAO.getInstance(client);
        String result = tag_DAO.PrintALLTag_S();
        //tr.close();
        return result;
    }
    
}
